package com.kun.springbootorder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kun.springbootorder.entity.Order;
import com.kun.springbootorder.entity.OrderMessage;
import com.kun.springbootorder.mapper.OrderMapper;
import com.kun.springbootorder.mapper.OrderMessageMapper;
import com.kun.springbootorder.service.OrderMessageService;
import com.kun.springbootorder.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kunkun
 * @since 2025-02-25
 */
@Service
public class OrderMessageServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderMessageService {
    @Autowired
    public OrderMessageMapper orderMessageMapper;

    @Override
    public Integer insertOrderMessage(OrderMessage orderMessage) {
        int num = orderMessageMapper.insert(orderMessage);
        return num;
    }

    @Override
    public Integer updateStatus(Integer orderId,Boolean status) {

        OrderMessage message = orderMessageMapper.selectById(orderId);
        if (status){
            message.setStatus(1);
        }else {
            message.setStatus(0);
        }
        int num = orderMessageMapper.updateById(message);

        return num;
    }

    @Override
    public List<OrderMessage> queryOrderMessagesByStatus(Boolean status) {

        QueryWrapper<OrderMessage> wrapper = new QueryWrapper<>();
        if (status){
            wrapper.eq("status",1);
        }else{
            wrapper.eq("status",0);
        }
        List<OrderMessage> list = orderMessageMapper.selectList(wrapper);

        return list;
    }

}
